﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace UFrame
{
    public class OURotate : MonoBehaviour
    {
        public float speed = 4f;
        private float angle = 0f;
        public UpdateRotate moveState = UpdateRotate.FixedMovement;
        public bool isAxisY = false;

        public void ResetAngle()
        {
            angle = 0;
        }

        public void Update()
        {
            if (moveState == UpdateRotate.UpdateMovement)
            {
                angle += speed * Time.deltaTime;
                if (isAxisY)
                    this.transform.rotation = Quaternion.Euler(0, angle, 0);
                else
                    this.transform.rotation = Quaternion.Euler(0, 0, angle);
            }
        }

        public void FixedUpdate()
        {
            if (moveState == UpdateRotate.FixedMovement)
            {
                angle += speed * Time.fixedDeltaTime;
                if (isAxisY)
                    this.transform.rotation = Quaternion.Euler(0, angle, 0);
                else 
                    this.transform.rotation = Quaternion.Euler(0, 0, angle);
            }
        }

        public enum UpdateRotate
        {
            FixedMovement,
            UpdateMovement,
        }
    }
}